<template>
  <div class="home">
    <div class="student-search">
      <input v-model="studentId" placeholder="请输入学号" />
      <button @click="searchStudent">查找</button>
    </div>
    <div v-if="foundStudent" class="student-info">
      <h3>学生信息</h3>
      <p>学号: {{ foundStudent.id }}</p>
      <p>姓名: {{ foundStudent.name }}</p>
      <p>年龄: {{ foundStudent.age }}</p>
      <p>专业: {{ foundStudent.zhuanye }}</p>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      studentId: '', 
      foundStudent: null 
    };
  },
  methods: {
    searchStudent() {
      const students = [
        { id: '1001', name: '张三', age: '19' ,zhuanye: '计算机科学与技术'},
        { id: '1002', name: '李四', age: '18' ,zhuanye: '法学'},
        { id: '1003', name: '王五', age: '20' ,zhuanye: '汉语言文学'}
      ];
      this.foundStudent = students.find(student => student.id === this.studentId);
      if (!this.foundStudent) {
        alert('未找到该学号的学生信息');
      }
    }
  }
};
</script>

<style scoped>
.student-search {
  margin-bottom: 20px;
}
input {
  padding: 5px;
  margin-right: 10px;
}
button {
  padding: 5px 10px;
  background-color: #4CAF50;
  color: white;
  border: none;
  cursor: pointer;
}
.student-info {
  border: 1px solid #ccc;
  padding: 10px;
  margin-top: 20px;
}
</style>